{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_griewank:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Griewank\n",
    "\n",
    "The Griewank function has many widespread local minima, which are regularly distributed. The complexity is shown in the zoomed-in plots. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f(x) & = & \\; \\sum_{n=1}^n \\; \\frac{x_i^2}{4000} - \\prod_{n=1}^n \\cos \\Bigg( \\frac{x_i}{\\sqrt{i}} \\Bigg) + 1 \\\\[4mm]\n",
    "&&-600 \\leq x_i \\leq 600 \\quad i=1 \\ldots,n \\\\[4mm]\n",
    "\\end{split}\n",
    "\\end{align}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$f(x^*) = 0 \\; \\text{at} \\; x^* = (0,\\ldots,0) $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Contour**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.visualization.fitness_landscape import FitnessLandscape\n",
    "\n",
    "problem = get_problem(\"griewank\", n_var=1)\n",
    "plot = FitnessLandscape(problem, _type=\"surface\", n_samples=1000)\n",
    "plot.do()\n",
    "plot.apply(lambda ax: ax.set_xlim(-200, 200))\n",
    "plot.apply(lambda ax: ax.set_ylim(-1, 13))\n",
    "plot.show()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
